package br.usp.poli.compilador2008.lexical;
//An array to store the produced tokens while the lexical analyser delivers it
public class TokenSet {
	
	private Token[] tokens;
	private int size;
	private int used;
	
	public TokenSet(){
		
		this.size = 50;
		this.tokens = new Token[size];
		this.used = 0;
	}
	
	// Add a token
	public void addToken(Token in){	
			if(used < size) {
				this.used=this.used+1;
				this.tokens[used-1]=in;
				System.out.println("Token Adicionado: " + in.toString());
			}
			else {
				size = size * 2;

				Token[] temp = new Token[size];
				System.arraycopy(tokens, 0, temp, 0, tokens.length);
				tokens = temp;
				used = used+1;
				tokens[used-1]=in;
				System.out.println("Token Adicionado: " + in.toString());
			}
		}
	
	// Returns how many tokens are stored
	public int getlength(){
		return this.tokens.length;
	}
	
	// Returns a token of a given position
	public Token getToken(int position){
		if(position<tokens.length){
			return this.tokens[position];
		}
		else return null;
	}
}
